$(document).ready(function(){
	

	var screenwidth, screenheight, mytop, getPosLeft, getPosTop
	screenwidth = $(window).width();
	screenheight = $(window).height();
	//获取滚动条距顶部的偏移
	mytop = $(document).scrollTop();
	//计算弹出层的left
	getPosLeft = screenwidth / 2 - 260;
	//计算弹出层的top
	getPosTop = screenheight / 2 - 150;
	//css定位弹出层
	$("#deptTree").css({ "left": getPosLeft, "top": getPosTop });
	//当浏览器窗口大小改变时
	$(window).resize(function() {
		screenwidth = $(window).width();
		screenheight = $(window).height();
		mytop = $(document).scrollTop();
		getPosLeft = screenwidth / 2 - 200;
		getPosTop = screenheight / 2 - 150;
		$("#deptTree").css({ "left": getPosLeft, "top": getPosTop+ mytop  });
	});
	//当拉动滚动条时，弹出层跟着移动
	$(window).scroll(function() {
		screenwidth = $(window).width();
		screenheight = $(window).height();
		mytop = $(document).scrollTop();
		getPosLeft = screenwidth / 2 - 200;
		getPosTop = screenheight / 2 - 150;
		$("#deptTree").css({ "left": getPosLeft, "top": getPosTop+ mytop  });	 
	}); 
	 //获取页面文档的高度
	 var docheight = $(document).height();
	//追加一个层，使背景变灰
	$("body").append("<div id='greyBackGround'></div>");
	$("#greyBackGround").css({ "opacity": "0.1", "height": docheight });

	
	$("#queryEmp").click(function(){
		$("#queryForm").submit();
	});
	
	
	//清空			 		 
	$("#clean").click(function(){
		$("#empName")[0].value="";
		$("#contact")[0].value="";
		$("#mail")[0].value="";
		$("#roleId").val("");
		//$("#deptId").val("");
		$("#queryDeptId").val("");
		$("#queryTempDeptId").val("");
	});
	
	 $("#deptTreeBtnCancel").click(function(){
		 	$("#greyBackGround").css("display","none");
		 	$("#deptTree").css("display","none");
	});
	$("#queryDeptTreeBtnConfirm").click(function(){
		var selectedNodeId="";
		var selectedNodeName="";
		var treeObj=$.fn.zTree.getZTreeObj("treeDemo");
		nodes=treeObj.getSelectedNodes();
		 for ( var int = 0; int < nodes.length; int++){
			 var node = nodes[int];
			 selectedNodeId = node.id;
			 selectedNodeName = node.name;
			 break;
		} 
	     if(selectedNodeId==""){
	     	alert("请选择部门!");
	     	return;
	     }
		$("#queryDeptId").val(selectedNodeId);
		$("#queryTempDeptId").val(selectedNodeName);
	 	$("#greyBackGround").css("display","none");
	 	$("#deptTree").css("display","none");
	});
	
	var setting = {	
			view: {selectedMulti:false},data: {keep: {parent:true,leaf:true},simpleData: {enable: true}},
			callback: {beforeDrag: beforeDrag}
	};
	function beforeDrag(treeId, treeNodes){
		return false;
	}
	$.fn.zTree.init($("#treeDemo"), setting, zNodes);
});

function bathApproval(approvalStatus){
	var empnoStr="";
	var list = $("input[id^=empId_][type='checkbox']:checked");
	if(list.length>0){
		for(var int = 0; int < list.length; int++){
			var empno = list[int].id.replace("empId_","");
			if(empnoStr==""){
				empnoStr=empno;
			}else{
				empnoStr = empnoStr+","+empno;
			}	
		}
	}
	if(empnoStr==""){
		alert("请选择记录!");
		return;
	}
	 $("#empnoStr").val(empnoStr);
	 $("#approvalStatus").val(approvalStatus);
	 $("#approvalForm").attr('action',"../../../ruleSet/approval/employeeSetApproval/bathApproval");
	 $("#approvalForm").submit();
	 
	 
	
}

function approval(empno,approvalStatus){
	$("#empno").val(empno);
	$("#approvalStatus")[0].value=approvalStatus;
	$("#approvalForm").submit();
}


function queryDeptTree(){
	 $("#queryDeptTreeBtnConfirm").css("display","block");
	 $("#greyBackGround").css("display","block");
	 $("#deptTree").fadeIn("slow"); 
}

function selectAll(){
	if($("#selectAll").attr("checked")==true){
		$('input[id^=empId_]').attr("checked",true); 
	}else{
		$('input[id^=empId_]').attr("checked",false); 
		
	}
}


